const fs = require('fs');
const path = require('path');

console.log('🔍 检查NestJS应用py_name字段更新...\n');

// 检查实体类更新
console.log('=== 检查实体类更新 ===');
const entityPath = 'src/entities/deputy-general-base.entity.ts';
if (fs.existsSync(entityPath)) {
  const entityContent = fs.readFileSync(entityPath, 'utf8');
  if (entityContent.includes('py_name')) {
    console.log('✅ DeputyGeneralBase实体类已包含py_name字段');
    
    // 检查字段定义
    const pyNameMatch = entityContent.match(/@Column\({[^}]*py_name[^}]*}\)/);
    if (pyNameMatch) {
      console.log('✅ py_name字段定义正确');
      console.log(`   字段定义: ${pyNameMatch[0]}`);
    } else {
      console.log('❌ py_name字段定义可能有问题');
    }
  } else {
    console.log('❌ DeputyGeneralBase实体类缺少py_name字段');
  }
} else {
  console.log('❌ 实体类文件不存在');
}

// 检查服务类更新
console.log('\n=== 检查服务类更新 ===');
const servicePath = 'src/services/deputy-general.service.ts';
if (fs.existsSync(servicePath)) {
  const serviceContent = fs.readFileSync(servicePath, 'utf8');
  if (serviceContent.includes('py_name: pd.deputy.base?.py_name')) {
    console.log('✅ DeputyGeneralService已包含py_name字段返回');
  } else {
    console.log('❌ DeputyGeneralService缺少py_name字段返回');
  }
  
  // 检查接口导入
  if (serviceContent.includes('DeputyGeneralListResponse')) {
    console.log('✅ 服务类已导入TypeScript接口');
  } else {
    console.log('❌ 服务类缺少TypeScript接口导入');
  }
} else {
  console.log('❌ 服务类文件不存在');
}

// 检查控制器更新
console.log('\n=== 检查控制器更新 ===');
const controllerPath = 'src/modules/deputy-general/deputy-general.controller.ts';
if (fs.existsSync(controllerPath)) {
  const controllerContent = fs.readFileSync(controllerPath, 'utf8');
  if (controllerContent.includes('DeputyGeneralListResponse')) {
    console.log('✅ 控制器已使用TypeScript接口');
  } else {
    console.log('❌ 控制器缺少TypeScript接口');
  }
} else {
  console.log('❌ 控制器文件不存在');
}

// 检查接口定义文件
console.log('\n=== 检查接口定义文件 ===');
const interfacePath = 'src/interfaces/deputy-general.interface.ts';
if (fs.existsSync(interfacePath)) {
  const interfaceContent = fs.readFileSync(interfacePath, 'utf8');
  if (interfaceContent.includes('py_name?: string')) {
    console.log('✅ 接口定义文件已包含py_name字段');
  } else {
    console.log('❌ 接口定义文件缺少py_name字段');
  }
} else {
  console.log('❌ 接口定义文件不存在');
}

// 检查TypeScript编译
console.log('\n=== 检查TypeScript编译 ===');
try {
  const { execSync } = require('child_process');
  console.log('正在检查TypeScript编译...');
  execSync('npx tsc --noEmit', { stdio: 'pipe' });
  console.log('✅ TypeScript编译检查通过');
} catch (error) {
  console.log('❌ TypeScript编译检查失败:');
  console.log(error.stdout?.toString() || error.message);
}

console.log('\n🎉 NestJS应用py_name字段更新检查完成！');
